/*** 
 * @Author: wq
 * @Date: 2021-07-20 22:06:40
 * @LastEditTime: 2021-07-20 22:35:38
 * @LastEditors: wq
 * @Description: 
 * @FilePath: /opencv_camera/code/WinInfo/src/screen.cpp
 * @CSDN： https://blog.csdn.net/u011218356 
 * @Git:  https://github.com/WQuit 
 * @Email:  779508400@qq.com  
 * @    星河灿烂，你是人间烟火
 */

#include "screen.h"
#include <iostream>

screen::screen(/* args */)
{
}

screen::~screen()
{
}

void screen::showInfo()
{
    Display *display = XOpenDisplay(NULL);
    Window window = DefaultRootWindow(display);
    int monitors = 0;
    XRRMonitorInfo* info = XRRGetMonitors(display, window, True, &monitors);
    for(int i = 0; i < monitors; i++)
    {
        std::cout << "XRRMonitorInfo: " << " primary:"  << info[i].primary  << "number:" << i << " x:" << info[i].x << " y:" << info[i].y << " width:" << info[i].width << " height:" << info[i].height \
            << " widthmm:" << info[i].mwidth << " heightm:" << info[i].mheight << std::endl;
    }
    XRRFreeMonitors(info);
    XFree(display);
}

std::list<screenInfo> screen::infoList()
{
    std::list<screenInfo> infoList;
    Display *display = XOpenDisplay(NULL);
    Window window = DefaultRootWindow(display);
    int monitors = 0;
    XRRMonitorInfo* info = XRRGetMonitors(display, window, True, &monitors);
    for(int i = 0; i < monitors; i++)
    {
        infoList.push_back({ (info[i].primary) ? true : false, i, info[i].x, info[i].y, info[i].width, info[i].height, info[i].mwidth, info[i].mheight});
    }
    XRRFreeMonitors(info);
    XFree(display);
    return infoList;
}